home *** CD-ROM | disk | FTP | other *** search
/ PC Users 8 / Cd Pc Users extra 8.iso / prog / inst / firstimp / vcimpres.z / sun32.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-11-07  |  9.8 KB  |  302 lines

  1. VERSION 5.00
  2. Object = "{335C3C4F-E3F2-11D0-87E8-00A0C903B29D}#5.0#0"; "VCFI5.OCX"
  3. Begin VB.Form Form1 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "LightSource Vector Example"
  6.    ClientHeight    =   6735
  7.    ClientLeft      =   1170
  8.    ClientTop       =   1515
  9.    ClientWidth     =   9435
  10.    Icon            =   "sun32.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    PaletteMode     =   1  'UseZOrder
  15.    ScaleHeight     =   6735
  16.    ScaleWidth      =   9435
  17.    Begin VtChartLib.VtChart VtChart1 
  18.       Height          =   6675
  19.       Left            =   0
  20.       TabIndex        =   13
  21.       Top             =   0
  22.       Width           =   7335
  23.       _ExtentX        =   12938
  24.       _ExtentY        =   11774
  25.       _0              =   $"sun32.frx":030A
  26.       _1              =   $"sun32.frx":070F
  27.       _2              =   $"sun32.frx":0B14
  28.       _3              =   $"sun32.frx":0F19
  29.       _4              =   $"sun32.frx":131E
  30.       _5              =   $"sun32.frx":1723
  31.       _6              =   $"sun32.frx":1B28
  32.       _7              =   $"sun32.frx":1F2D
  33.       _8              =   $"sun32.frx":2332
  34.       _9              =   $"sun32.frx":2737
  35.       _10             =   $"sun32.frx":2B3C
  36.       _11             =   $"sun32.frx":2F41
  37.       _12             =   $"sun32.frx":3346
  38.       _13             =   $"sun32.frx":374B
  39.       _14             =   $"sun32.frx":3B50
  40.       _count          =   15
  41.       _ver            =   1
  42.    End
  43.    Begin VB.Frame Frame2 
  44.       Caption         =   " Set Vector By Time "
  45.       Height          =   1935
  46.       Left            =   7440
  47.       TabIndex        =   5
  48.       Top             =   3420
  49.       Width           =   1815
  50.       Begin VB.CommandButton cmdSetTime 
  51.          Caption         =   "Set Time"
  52.          Height          =   315
  53.          Left            =   360
  54.          TabIndex        =   8
  55.          Top             =   1440
  56.          Width           =   1155
  57.       End
  58.       Begin VB.TextBox txtTime 
  59.          Height          =   285
  60.          Left            =   360
  61.          TabIndex        =   6
  62.          Text            =   "Time"
  63.          Top             =   960
  64.          Width           =   1155
  65.       End
  66.       Begin VB.Label Label1 
  67.          Caption         =   "0 = Midnight  0.5 = Noon"
  68.          BeginProperty Font 
  69.             Name            =   "Arial"
  70.             Size            =   9
  71.             Charset         =   0
  72.             Weight          =   400
  73.             Underline       =   0   'False
  74.             Italic          =   0   'False
  75.             Strikethrough   =   0   'False
  76.          EndProperty
  77.          Height          =   495
  78.          Left            =   420
  79.          TabIndex        =   7
  80.          Top             =   360
  81.          Width           =   1155
  82.       End
  83.    End
  84.    Begin VB.Frame Frame1 
  85.       Caption         =   " Light Vector "
  86.       Height          =   2115
  87.       Left            =   7440
  88.       TabIndex        =   1
  89.       Top             =   1020
  90.       Width           =   1815
  91.       Begin VB.CommandButton cmdSetVector 
  92.          Caption         =   "Set Vector"
  93.          Height          =   315
  94.          Left            =   360
  95.          TabIndex        =   9
  96.          Top             =   1620
  97.          Width           =   1155
  98.       End
  99.       Begin VB.TextBox txtX 
  100.          Height          =   285
  101.          Left            =   420
  102.          TabIndex        =   4
  103.          Text            =   "X"
  104.          Top             =   420
  105.          Width           =   1215
  106.       End
  107.       Begin VB.TextBox txtZ 
  108.          Height          =   285
  109.          Left            =   420
  110.          TabIndex        =   3
  111.          Text            =   "Z"
  112.          Top             =   1140
  113.          Width           =   1215
  114.       End
  115.       Begin VB.TextBox txtY 
  116.          Height          =   285
  117.          Left            =   420
  118.          TabIndex        =   2
  119.          Text            =   "Y"
  120.          Top             =   780
  121.          Width           =   1215
  122.       End
  123.       Begin VB.Label Label2 
  124.          Caption         =   "Z:"
  125.          Height          =   255
  126.          Index           =   2
  127.          Left            =   180
  128.          TabIndex        =   12
  129.          Top             =   1200
  130.          Width           =   195
  131.       End
  132.       Begin VB.Label Label2 
  133.          Caption         =   "Y:"
  134.          Height          =   255
  135.          Index           =   1
  136.          Left            =   180
  137.          TabIndex        =   11
  138.          Top             =   840
  139.          Width           =   195
  140.       End
  141.       Begin VB.Label Label2 
  142.          Caption         =   "X:"
  143.          Height          =   255
  144.          Index           =   0
  145.          Left            =   180
  146.          TabIndex        =   10
  147.          Top             =   480
  148.          Width           =   195
  149.       End
  150.    End
  151.    Begin VB.CommandButton cmdAnimate 
  152.       Caption         =   "Animate"
  153.       Height          =   435
  154.       Left            =   7800
  155.       TabIndex        =   0
  156.       Top             =   5760
  157.       Width           =   1155
  158.    End
  159. Attribute VB_Name = "Form1"
  160. Attribute VB_GlobalNameSpace = False
  161. Attribute VB_Creatable = False
  162. Attribute VB_PredeclaredId = True
  163. Attribute VB_Exposed = False
  164. Option Explicit
  165. Sub LoadSufaceData(filename$)
  166.    Dim rows%, cols%, i%, j%, junk$, value#
  167.    On Error GoTo LoadSufaceDataError
  168.    Open filename For Input As #1
  169.    Input #1, junk, rows
  170.    Input #1, junk, cols
  171.    With VtChart1
  172.       .RowCount = rows
  173.       .ColumnCount = cols
  174.       With .DataGrid
  175.          For i = 1 To rows
  176.             For j = 1 To cols
  177.                Input #1, value
  178.                .SetData i, j, value, False
  179.             Next j
  180.          Next i
  181.       End With
  182.    End With
  183.    Close #1
  184.       
  185.    Exit Sub
  186. LoadSufaceDataError:
  187.    MsgBox Error
  188. End Sub
  189. Sub FormatSurfaceChart()
  190.    Dim i As Integer
  191.    Dim attr As Object
  192.    With VtChart1
  193.       .chartType = VtChChartType3dSurface
  194.       .Backdrop.Fill.Style = VtFillStyleBrush
  195.       .Backdrop.Fill.Brush.FillColor.Set 64, 192, 192
  196.       
  197.       With .Plot
  198.          .Light.EdgeVisible = False
  199.          .Elevation.Surface.WireframePen.Style = VtPenStyleNull
  200.          .Elevation.Surface.DisplayType = VtChSurfaceDisplayTypeCBands
  201.          .PlotBase.BaseHeight = 0
  202.          .Wall.Pen.Style = VtPenStyleNull
  203.          
  204.          .Axis(VtChAxisIdZ).AxisGrid.MajorPen.Style = VtPenStyleNull
  205.          .Axis(VtChAxisIdZ).AxisScale.Hide = True
  206.          
  207.          .Axis(VtChAxisIdY).AxisGrid.MajorPen.Style = VtPenStyleNull
  208.          .Axis(VtChAxisIdY).AxisScale.Hide = True
  209.          
  210.          .Axis(VtChAxisIdY2).AxisGrid.MajorPen.Style = VtPenStyleNull
  211.          .Axis(VtChAxisIdY2).AxisScale.Hide = True
  212.          
  213.          .Axis(VtChAxisIdX).AxisGrid.MajorPen.Style = VtPenStyleNull
  214.          .Axis(VtChAxisIdX).AxisScale.Hide = True
  215.          
  216.          .View3d.Set 58, 16
  217.          
  218.          With .Elevation
  219.             '' Set up the contours
  220.             .AutoValues = False
  221.             .ColorType = VtChContourColorTypeManual
  222.             
  223.             With .Attributes
  224.                
  225.                For i = 1 To .Count - 5
  226.                   .Remove (i)
  227.                Next i
  228.                
  229.                '' Set contour values and their color
  230.                .Item(1).value = 0
  231.                .Item(2).value = 0.01
  232.                .Item(3).value = 43
  233.                .Item(4).value = 43.5
  234.                .Item(5).value = 50
  235.                
  236.                .Item(1).Brush.FillColor.Set 0, 0, 202
  237.                .Item(2).Brush.FillColor.Set 0, 0, 202
  238.                .Item(3).Brush.FillColor.Set 10, 128, 10
  239.                .Item(4).Brush.FillColor.Set 210, 210, 210
  240.                .Item(5).Brush.FillColor.Set 255, 255, 255
  241.             End With
  242.             
  243.             '' For Each attr In VtChart1.Plot.Elevation.Attributes
  244.             ''    attr.Brush.Style = VtBrushStyleSolid
  245.             '' Next attr
  246.          
  247.          End With
  248.       
  249.       End With
  250.    End With
  251. End Sub
  252. Sub SetLightForTime(ch As Object, theTime!)
  253. '' Times are in the spreadsheet serial number format where
  254. '' 1 = a day so zero = midnight and 0.5 = noon. For trig
  255. '' functions Pi/2 = midnight and 3Pi/2 = noon. The code
  256. '' below maps time to light source coordinates. We also throw
  257. '' in some ambient intensity to simulate the reflected light
  258. '' during midday. Note that we are setting the direction
  259. '' of the sun's rays, not its position. See the associated
  260. '' readme for chart/light coordinate systems.
  261.    Const r = 20
  262.    Const HALFPI = 1.5708
  263.    Dim radians!, x!, y!, z!
  264.    radians = (theTime / 0.25) * HALFPI + HALFPI
  265.    x = r * Cos(radians)
  266.    y = r * Sin(radians)
  267.    z = -0.1 + theTime
  268.    ch.Plot.Light.LightSources.Item(1).Set x, y, z, 1
  269.    ch.Plot.Light.AmbientIntensity = 1.25 * (IIf(theTime > 0.5, 1 - theTime, theTime))
  270.    txtX.Text = Str(x)
  271.    txtY.Text = Str(y)
  272.    txtZ.Text = Str(z)
  273. End Sub
  274. Private Sub cmdAnimate_Click()
  275.    Static when!
  276.    For when = 0 To 1 Step 0.05
  277.       SetLightForTime VtChart1, when
  278.       'VtChart1.Refresh
  279.       txtTime.Text = Format(when, "hh:mm")
  280.       DoEvents
  281.       
  282.    Next when
  283. End Sub
  284. Private Sub cmdSetTime_Click()
  285.    Dim theTime!
  286.    theTime = Val(txtTime.Text)
  287.    If theTime >= 0 And theTime <= 1 Then
  288.       txtTime.Text = Format(theTime, "hh:mm")
  289.       SetLightForTime VtChart1, theTime
  290.    Else
  291.       MsgBox "Time must be a number between 0 and 1."
  292.    End If
  293.       
  294. End Sub
  295. Private Sub cmdSetVector_Click()
  296.    VtChart1.Plot.Light.LightSources.Item(1).Set Val(txtX.Text), Val(txtY.Text), Val(txtZ.Text), 1
  297. End Sub
  298. Private Sub Form_Load()
  299.    LoadSufaceData App.Path & "\surfdata.txt"
  300.    FormatSurfaceChart
  301. End Sub
  302.